home *** CD-ROM | disk | FTP | other *** search
- /* AEObj.c
- * Utilities for dealing with Apple Event Objects (making descriptors, etc.)
- * ©1992 Working Software, Inc.
- * This source code is copyrighted. Permission is granted to use the Word Services
- * portion of the Writeswell Jr. source code in your own programs, but you
- * may not distribute the Writeswell Jr. word-processor code as a
- * commercial product. If you modify the code, please do not call it
- * Writeswell Jr. (or Writeswell.) This will ensure that people understand the
- * program and don’t have to deal with a number of different versions with
- * who-knows-what going on in the code.
- *
- * Writeswell Jr. and Writeswell are trademarks of Working Software, Inc.
- * 18 Dec 91 Mike Crawford
- */
-
- #include <AppleEvents.h>
- #include <AEObjects.h>
- #include <AERegistry.h>
- #include "TBConstants.h"
- #include "TBGlobals.h"
- #include "AEObj.h"
- #include "ObWind.h"
- #include "ObText.h"
- #include "ObOspec.h"
- #include "Gripe.h"
-
- OSErr InstallMyAccessors( void );
- pascal OSErr MyCountProc(DescType desiredType,
- DescType containerClass,
- const AEDesc *container,
- long *result);
- pascal OSErr MyDisposeTokenProc(AEDesc *unneededToken);
- OSErr InstallMyCoercers( void );
-
- OSErr InitAEObjStuff( void )
- {
- OSErr err;
-
- err = AEObjectInit();
- if ( err ){
- Gripe( "\pAEObjectInit failed" );
- return err;
- }
-
- err = InstallMyAccessors();
- if ( err ){
- Gripe( "\pInstallMyAccessors failed" );
- return err;
- }
-
- /* Install the callback functions used by the AEObj parser */
- err = AESetObjectCallbacks((compareProcPtr)nil,
- (countProcPtr)MyCountProc,
- (disposeTokenProcPtr)MyDisposeTokenProc,
- (getMarkTokenProcPtr)nil,
- (markProcPtr)nil,
- (adjustMarksProcPtr)nil,
- (getErrDescProcPtr)nil);
-
- err = InstallMyCoercers();
- if ( err ){
- Gripe( "\pInstallMyCoercers failed" );
- return err;
- }
-
- return noErr;
- }
-
- OSErr InstallMyAccessors( void )
- {
- OSErr err;
-
- /* We install the accessors to get various objects from various containers */
-
- /* Get a Window element from an application (null) container */
- err = AEInstallObjectAccessor(cWindow,
- typeNull,
- (accessorProcPtr)WindFromNull,
- 0,
- false);
-
- /* Get any property from a window container */
- err = AEInstallObjectAccessor( typeProperty,
- cWindow,
- (accessorProcPtr)PropFromWind,
- 0,
- false);
-
- /* Get text from a window container */
- err = AEInstallObjectAccessor( cText,
- cWindow,
- (accessorProcPtr)TextFromWind,
- 0,
- false);
-
- /* Get a word from a TextEdit text container */
- err = AEInstallObjectAccessor( cWord,
- typeTEText,
- (accessorProcPtr)WordFromTEText,
- 0,
- false);
-
- /* Get a char (or set thereof) from a TextEdit text container */
- err = AEInstallObjectAccessor( cChar,
- typeTEText,
- (accessorProcPtr)CharFromTEText,
- 0,
- false);
-
- /* Get any property from a text container */
- err = AEInstallObjectAccessor( typeProperty,
- typeTEText,
- (accessorProcPtr)PropFromTEText,
- 0,
- false);
-
- /* Get an object specifier from a window container (for Word Services) */
- err = AEInstallObjectAccessor( typeObjectSpecifier,
- cWindow,
- (accessorProcPtr)OspecFromWind,
- 0,
- false);
-
- return noErr;
- }
-
- OSErr InstallMyCoercers( void )
- {
- OSErr err;
-
- err = AEInstallCoercionHandler( typeChar,
- typePString,
- (ProcPtr)TextPtrToPString,
- 0L,
- false, /* Pass a pointer not a descriptor */
- false ); /* Application table, not System */
- if ( err ){
- Gripe( "\pAEInstallCoercionHandler failed on TextPtrToPString" );
- return err;
- }
-
- return noErr;
- }
-
- /* This is a single routine that must know how to count each of the kinds of objects
- * that are used in this application. Eventually we should have it call functions
- * that are in the ObjXXX files.
- */
-
- pascal OSErr MyCountProc(DescType desiredType,
- DescType containerClass,
- const AEDesc *container,
- long *result)
- {
- OSErr err = noErr;
-
- switch ( desiredType ){
- case cWindow:
- *result = ( gDocWindow ? 1 : 0 );
- break;
- default:
- Gripe( "\pTrying to count an object I do not know about" );
- err = errAENoSuchObject;
- break;
- }
-
- return err;
- }
-
- pascal OSErr MyDisposeTokenProc(AEDesc *unneededToken)
- {
- OSErr myErr = noErr;
-
- /* In most cases we just toss out the token descriptor. We may need to do more
- * stuff in the event the the token handle actually points to some real data.
- */
-
- switch (unneededToken->descriptorType) {
- case cWindow:
- myErr = AEDisposeDesc(unneededToken);
- break;
-
- default:
- /* I default to just disposing of the token, ne ces pa */
- AEDisposeDesc(unneededToken);
- break;
- }
- return(myErr);
- }
-
- OSErr MakeTextDesc( AEDesc *descPtr )
- {
-
- return noErr;
- }